package com.ysd.servlet;

import java.io.IOException;
import java.util.List;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.ysd.dao.impl.NewsDaoImpl;
import com.ysd.dao.impl.NewsDetailsDaoImpl;
import com.ysd.entity.NewsClassify;
import com.ysd.entity.NewsDetails;


public class NewsServlet extends HttpServlet {
	
	protected void doGet(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException {
		//咨询的分类
		NewsDaoImpl news = new NewsDaoImpl();
		List<NewsClassify> newsList = news.getNews();
		request.setAttribute("newsList", newsList);
		
		//通过Id查询新闻详情
		//接受前台传来的参数
		int cId = Integer.parseInt(request.getParameter("newsClassifyId"));
		NewsDetailsDaoImpl nDetails = new NewsDetailsDaoImpl();
		List<NewsDetails> newList = nDetails.getNDetails(cId);
		request.setAttribute("newList", newList);
		request.getRequestDispatcher("article_list.jsp").forward(request, response);
	}

	
	protected void doPost(HttpServletRequest request, HttpServletResponse response) 
			throws ServletException, IOException {
		
		doGet(request, response);
	}

}
